package dt

import scala.collection.mutable.ListBuffer

object DT_82 {

  def main(args: Array[String]): Unit = {
    val list = List(1,2,3,4,5,6,7,8,9,10)
    val res1 = increment(list)
    val res2 = incrementMoreEffective(list)
    val res3 = incrementMostEffective(list)
    /*res1.foreach(print)
    res2.foreach(print)
    res3.foreach(print)*/
    ListBuffer
    list.map(_ +1).foreach(println)
  }


  def increment(list:List[Int]): List[Int] = list match {
    case List() => List()
    case head :: tail => head +1 ::increment(tail)
  }

  def incrementMoreEffective(list:List[Int]): List[Int] = {
    var res = List[Int]()
    for(element <- list) res = res ::: List(element + 1)
    res
  }

  /**
    * list buffer
    * @param list
    * @return
    */
  def incrementMostEffective(list:List[Int]): List[Int] = {
    var buffer = new ListBuffer[Int]
    for(element <- list) buffer += element +1
    buffer.toList
  }




}
